﻿var TopLayoutSettings = {
    defaults: {
        size: "auto"
		, minSize: 5
        , resizable: false
		, paneClass: "ui-layout-pane"
		, resizerClass: "ui-layout-resizer"
		, togglerClass: "ui-layout-toggler"
		, buttonClass: "ui-layout-button"
		, contentSelector: ".content"	// inner div to auto-size so only it scrolls, not the entire pane!
		, contentIgnoreSelector: "span"		// 'paneSelector' for content to 'ignore' when measuring room for content
		, togglerLength_open: 35			// WIDTH of toggler on north/south edges - HEIGHT on east/west edges
		, togglerLength_closed: 35			// "100%" OR -1 = full height
        , spacing_open: 0
        , spacing_closed: 0
		, hideTogglerOnSlide: true		// hide the toggler when pane is 'slid open'
		, togglerTip_open: "关闭面板"
		, togglerTip_closed: "打开面板"
		, resizerTip: "调节面板尺寸"
		, slidable: false
        //	effect defaults - overridden on some panes
		, fxName: "slide"		// none, slide, drop, scale
		, fxSpeed_open: 750
		, fxSpeed_close: 1500
		, fxSettings_open: { easing: "easeInQuint" }
		, fxSettings_close: { easing: "easeOutQuint" }
    }
    , north: {
        size: 109
    }
    , west: {
        size: 170
        , spacing_open: 5
        , spacing_closed: 5
    }
    , center: {
        minWidth: 100
		, minHeight: 100
    }
};

function changeSkin(li) {
    var skinArr = ["default", "red"];
    var n = -1;
    var skin = $(li).attr("skin");
    if (skin) {
        n = parseInt(skin, 10);
    }
    n = (++n) % skinArr.length;
    parkMSys.changeSkin(skinArr[n]);
    $(li).attr("skin", n);
}

function TreeRoot(treeData) {
    if (treeData.IsLeaf) {
        return "<ul class='treeroot'><li><span class='leaf'><a href='" + treeData.Url + "' target='ifmFuntion'>" + treeData.Text + "</a></span></li></ul>";
    }
    if (treeData.Url == "") {
        var s = "<ul class='treeroot'><li><span class='notleaf'>" + treeData.Text + "</span><ul>";
    }
    else {
        var s = "<ul class='treeroot'><li><span class='notleaf'><a href='" + treeData.Url + "' target='ifmFuntion'>" + treeData.Text + "</a></span><ul>";
    }
    $.each(treeData.LstMenu, function (i, v) {
        s += Tree(v);
    });
    return s + "</ul></li>";
}

function Tree(treeData) {
    if (treeData.IsLeaf) {
        return "<li><span class='leaf'><a href='" + treeData.Url + "' target='ifmFuntion'>" + treeData.Text + "</a></span></li>";
    }
    if (treeData.Url == "") {
        var s = "<li><span class='notleaf'>" + treeData.Text + "</span><ul>";
    }
    else {
        var s = "<li><span class='notleaf'><a href='" + treeData.Url + "' target='ifmFuntion'>" + treeData.Text + "</a></span><ul>";
    }
    $.each(treeData.LstMenu, function (i, v) {
        s += Tree(v);
    });
    return s + "</ul></li>";
}

function SetLeftFucList(leftFucId) {

    $.ajax({
        url: "proxy.aspx", type: "post", dataType: "json"
        , data: { method: "GetLeftMenu", id: leftFucId }
        , success: function (obj) {
            //                        alert(JSON.stringify(obj));
            if (obj.isInvalidUser) {
                alert("invalid user");
                return;
            }

            var s = "";

            $.each(obj, function (i, v) {
                s += TreeRoot(v);
            });

            $("#leftMenu").empty().append(s);


            $(".treeroot").treeview();

        }
    });
}

function init() {

    
}

$(function () {

    if (!IsOnLine()) {
        return;
    }

    $('body').show().layout(TopLayoutSettings);

    $(window).resize(function () {
        setTimeout(function () {
            AdjustIframeHeight("#ifmFuntion");
        }, 500);
    });

    $("#ifmFuntion").load(function () {
        AdjustIframeHeight("#ifmFuntion");
        $(this).contents().find("html,body").css({ width: "100%", border: "0px", padding: "0px", margin: "0px", left: "0px", top: "0px" });
        $(this).contents().find("body").height($(this).height()).css("overflow-y", "scroll");
    });

    $("#leftMenu>[flag=leftmenu]").each(function () {
        var rand0 = $(this);
        var tr = rand0.find(">table").addClass("title_box").find("tr").addClass("title");
        tr.find("td:first").addClass("menu_icon");
        tr.find("td:last").addClass("menu_alink");

        rand0.find(">div").addClass("m_box").addClass("menu_content");
    });

    $("#topMenu a:first").click();
});